package com.zkingsoft.actions.admin.web;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zkingsoft.anotations.RemoveRequestToken;
import com.zkingsoft.anotations.SaveRequestToken;
import com.zkingsoft.authority.MatrixAdapter;
import com.zkingsoft.constraint.BaseController;
import com.zkingsoft.model.web.WebAdcolumn;
import com.zkingsoft.pojo.AjaxResult;
import com.zkingsoft.pojo.PaginationVO;
import com.zkingsoft.services.web.WebAdcolumnService;
import com.zkingsoft.util.WebUtil;

/**
 * This field was generated by Zking.software.Codegen.
 * @date 2016-12-20 15:50
 */
@Controller
@RequestMapping(value = "admin/webAdcolumn")
public class WebAdcolumnController extends BaseController{

	@Resource
	private WebAdcolumnService webAdcolumnService;
	
	@Resource
	private MatrixAdapter matrixAdapter;
	
	
	
	//记录编辑前的值Before_Edit_Value
	public static final String BEV="WebAdcolumn_BEV";
	
	public static final String fnCode = "WebAdcolumn";
	public static final String search = fnCode + ":search";
	public static final String edit = fnCode + ":edit";
	public static final String del = fnCode + ":del";
	public static final String add = fnCode + ":add";
	
	/**
	 * 列表显示
	 */
	@RequestMapping(value = "/showList")
	public @ResponseBody AjaxResult showList(WebAdcolumn webAdcolumn, PaginationVO pageVo) {
		matrixAdapter.isBtnPermitted(search);
		return showList(webAdcolumnService, webAdcolumn, pageVo);
	}
   	
	/**
	 * 列表显示
	 */
	@RequestMapping(value = "/all")
	public @ResponseBody AjaxResult all() {
		return new AjaxResult(AjaxResult.STATUS_OK,webAdcolumnService.findByModel(null));
	}
   	
	
	/**
	 * 新增或者修改页面
	 */   
	@RemoveRequestToken	
   	@RequestMapping(value = "/addOrModify")
	public @ResponseBody AjaxResult addOrModify(WebAdcolumn webAdcolumn) {
		if (webAdcolumn.getColId() != null) {
	   		matrixAdapter.isBtnPermitted(edit);
	   		AjaxResult result=modify(webAdcolumnService, WebUtil.getSessionAttribute(this.BEV), webAdcolumn, "广告栏");
			WebUtil.removeSessionAttribute(this.BEV);
			return  result;
		} else {
			matrixAdapter.isBtnPermitted(add);
			return add(webAdcolumnService, webAdcolumn, "广告栏");
		}
	}
	
   	/**
	 * 进入修改界面
	 */   
	@SaveRequestToken
   	@RequestMapping(value = "/editForm")
	public String editForm(Long id) {
		matrixAdapter.isBtnPermitted(edit);
		WebAdcolumn webAdcolumn;
		if (id != null) {
			webAdcolumn = webAdcolumnService.findById(id);
			WebUtil.getRequest().setAttribute("obj", webAdcolumn);
			WebUtil.setSessionAttribute(this.BEV, webAdcolumn);
		}
		return "admin/web/adColumn-form";
	}
   	
   	
   	/**
	 * 删除
	 */  
 	@RequestMapping(value = "/del")
	public @ResponseBody AjaxResult del(String keys) {
		matrixAdapter.isBtnPermitted(del);
		return remove(webAdcolumnService, keys);
	}
 	
 	
 	/**
	 * 显示备注去重
	 */
	@RequestMapping(value = "/page")
	public @ResponseBody AjaxResult kb() {
		return new AjaxResult(AjaxResult.STATUS_OK,webAdcolumnService.findByRemark());
	}
	
	
	
 	
 	
 	
 	
  
}